﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ins = LEET.StandardModuals.Instructions;
using Compiled_Tests.Utils;
using LEET.CommonInterfaces.TestControls;
using LEET.LEETCommon;
using LEET.LEETCommon.WidgetLookup;
using Compiled_Tests;
using System.Windows.Automation;

namespace LEET.StandardModuals.Instructions.Actions
{
    public class SetVal : Ins.Action
    {
        string value;
        public SetVal(String[] args)
            : base(args)
        {
            value = "";
            for (int i = 3; i < args.Length; ++i)
            {
                value += args[i].Trim();
                if (args.Length > i + 1)
                    value += " | ";
            }
            value = LEET.LEETCommon.Utilities.Escape(value);
        }

        public static IAutomationActionResult StaticCall(IBox box, String element, String value)
        {
            AutomationElement e = WidgetFinder.Find(element, box.RootElement);
            Object obj;
            e.TryGetCurrentPattern(ValuePattern.Pattern, out obj);
            ValuePattern pattern = obj as ValuePattern;
            if (pattern != null)
                pattern.SetValue(value);
            return new AutomationActionResult();
        }

        public override String RenderStaticCall()
        {
            return "LEET.StandardModuals.Instructions.Actions.SetVal.StaticCall(Box, \"" + element + "\", \"" + value + "\")";
        }

        public override string PlainText()
        {
            string [] split = element.Split(',');
            return "Value of " + split[split.Length - 1] + " set to: " + value + " .";
        }
    }
}
